package Chapter2.Comparing.c7;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.InputMismatchException;
import java.util.Scanner;

public class ExceptionTest2 {
    public static void main(String[] args) throws FileNotFoundException {
        /*int a,b,c;
        System.out.println("请输入两个整数： ");
        Scanner scanner = new Scanner(System.in);
        try{
            a = scanner.nextInt();
            b = scanner.nextInt();
            c = a/b;
            System.out.println("result is: " + c);
        }
        catch (Exception e) {
            if (e instanceof InputMismatchException) {
                System.out.println("input is not integer");
            }
            else if(e instanceof ArithmeticException) {
                System.out.println("divisor cannot be zero");

            }
            else {
                System.out.println("unknow exception");
            }
        }
        System.out.println("end of program.");
    }*/

    /*public static void readFile() throws FileNotFoundException {
        File file = new File("d:\\xxx.jpg");
        FileInputStream fis = new FileInputStream(file);
    }*/
    try{
        int a = sum(-3,6);
        System.out.println(a);
    }
    catch (Exception e) {
        System.out.println(e.getMessage());
    }
    }
    public static int sum(int a, int b) {
        if (a<0||b<0){
            throw new MinusException("cannot resolve negative numbers");

        }
        return a+b;
    }

}
